package com.apps.ftapp.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.bean.CategoriesBean;
import com.apps.ftapp.model.LessonModel;
import com.apps.ftapp.util.Constant;
import com.apps.ftapp.util.DensityUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.List;

public class TiKuAdapter extends ArrayAdapter<CategoriesBean> {


    private int resource;
    private Context context;

    RoundedCorners roundedCorners = new RoundedCorners(20);
    //通过RequestOptions扩展功能
    RequestOptions options;


    public TiKuAdapter(Context context, int resource, List<CategoriesBean> objects) {

        super(context, resource, objects);
        this.resource = resource;
        this.context = context;
        int width = 0;
        int height = 0;

        width = DensityUtils.dp2px(context, (Constant.SCREEN_WIDTH - 20 - 20) / 3);
        height = width * 7 / 9;
        options = RequestOptions.centerCropTransform().placeholderOf(R.mipmap.ic_launcher).bitmapTransform(roundedCorners).override(width, height);


    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {


        CategoriesBean bean = getItem(position);
        ViewHolder holder = null;
        if (view == null) {
            view = LayoutInflater.from(getContext()).inflate(resource, null, false);
            holder = new ViewHolder();
            holder.pic = view.findViewById(R.id.tk_pic);
            holder.title = view.findViewById(R.id.tk_title);

            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        Glide.with(context).load(bean.getIcon()).apply(options)
                .into(holder.pic);


        return view;
    }


    private class ViewHolder {
        ImageView pic;
        TextView title;

    }


}
